/*
* Yahtzee 3.0 Client
* (c) Karl Puusepp & Tony Lepmets
* maiz & co, 2012
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Yahtzee {

	public static void main(String[] args) throws Exception {
		
		Socket clientSocket=null;
		BufferedReader in = null;
		PrintWriter out = null;
		
		String hostname = JOptionPane.showInputDialog(
    			null, "Sisesta serveri IP-aadress", "Yahtzee 3.0",
    			JOptionPane.INFORMATION_MESSAGE);
		
		int port = Integer.parseInt(JOptionPane.showInputDialog(
    			null, "Sisesta serveri port", "Yahtzee 3.0",
    			JOptionPane.INFORMATION_MESSAGE));
		
		//String hostname = "localhost";
		//int port = 6789;
		
		try {
			clientSocket = new Socket(hostname, port);
			in = new BufferedReader(
					new InputStreamReader(clientSocket.getInputStream()));
			out = new PrintWriter(
					new OutputStreamWriter(clientSocket.getOutputStream()), false);
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: "+hostname);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: "+hostname);
            System.exit(1);
        }
		
		JFrame frame = new JFrame("Yahtzee!");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		YahtzeeClient client = new YahtzeeClient(in, out);
		
		frame.setContentPane(client.panel);
		
		frame.setResizable(false);
		frame.setLocation(500,400); // raami asukoht ekraanil
		frame.pack();
		frame.setVisible(true);
		
		client.play();	
	}
	
}
